<template>
  <div>
    <div class="content">
      <div class="s-card" v-if="agent.roledec">
        <div class="s-card-text">{{ agent.roledec + "：" + agent.phone }}</div>
      </div>
      <div class="btn4" @click="reset">退出登录</div>
      <div class="card1" v-for="(item, index) in list" :key="index">

        <div class="card1-title">商户信息</div>

        <div style="display: flex;justify-content: space-around;">
          <div class="card1-text">商户名称：{{ item.name }}</div>
          <div class="card1-text">手机号：{{ item.phone }}</div>
        </div>
        <div style="display: flex;justify-content: space-around;">

          <div class="card1-text">类型：{{ item.roledec }}</div>
          <div class="card1-text">状态：{{ item.statedec }}
          <div class="btn-new"  @click="noAllow(item)" v-if="item.state == 1">禁用</div>
          <div class="btn-news"  @click="Allow(item)" v-else-if="item.state == 2">启用</div>
          </div>
        </div>
        <div style="display: flex;justify-content: space-around;">

          <div class="card1-text">店铺名称：{{ item.storename }}</div>
          <div class="card1-text">
            代金券金额：<span v-if="item.voucher" style="color: red">{{ item.voucher }}元</span>
          </div>
        </div>
        <div class="card1-text">注册时间：{{ item.time }}</div>
        <div style="display: flex;justify-content: space-around;" v-if="item.dec">

          <div class="card1-text" style="color:red">备注：{{ item.dec }}</div>
        </div>
        <div class="btn">
          <div class="btn1" @click="btn3(item)">修改余额</div>
          <div class="btn1" @click="btn4(item)">重置密码</div>
          <div class="btn2" @click="btn1(item)">变更记录</div>
          <div class="btn2" @click="btn2(item)">发放记录</div>
        </div>
      </div>
      <div class="addStore" @click="addMember">
        新增商户
      </div>
    </div>
  </div>
</template>

<script>
import { indexdata,resetPwd ,allow,ban} from "@/api/fulfil.js";
export default {
  name:'supertube',
  data() {
    return {
      agent: {},
      store: {},
      ticket: {},
      list: [],
    };
  },
  created() { },
  mounted() {
    /* let uid = localStorage.getItem("agentids");
    if (!uid) {
      this.$Toast("请先登录！");
      this.$router.push({
        path: "/login",
      });
    } else {
      this.getIndex();
    } */
  },
  activated() {
    let uid = localStorage.getItem("agentids");
    if (!uid) {
      this.$Toast("请先登录！");
      this.$router.push({
        path: "/login",
      });
    } else {
      this.getIndex();
    }
  },
  methods: {
    //新增商户
    addMember() {
      this.$router.push({
        path: "/addstore",
      });
    },
    //退出登录
    reset() {
      localStorage.removeItem("adminid");
      localStorage.removeItem("agentid");
      localStorage.removeItem("agentids");
      localStorage.removeItem("phone");
      localStorage.removeItem("password");
      localStorage.removeItem("role");
      this.$router.push({
        path: "/login",
      });
    },
    
    btn3(item) {
      localStorage.setItem("adminid", item.id);
      this.$router.push({
        path: "/supertubedit",
        query: { item: item },
      });
    },
    btn4(item){
      this.resetPwd(item);
    },
    //禁用
    noAllow(item){
      ban({
        adminid: localStorage.getItem("agentids"),
        agentid:item.id
      })
        .then((res) => {
         if(res.data.code == 0){
          this.$Toast("该店长账户禁用成功！");
          this.getIndex();
         }else{
          this.$Toast(res.data.msg);
         }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    //启用
    Allow(item){
      allow({
        adminid: localStorage.getItem("agentids"),
        agentid:item.id
      })
        .then((res) => {
         if(res.data.code == 0){
          this.$Toast("该店长账户启用成功！");
          this.getIndex();
         }else{
          this.$Toast(res.data.msg);
         }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    //重置密码
    resetPwd(item){
      resetPwd({
        adminid: localStorage.getItem("agentids"),
        agentid:item.id
      })
        .then((res) => {
         if(res.data.code == 0){
          this.$Toast("该店长密码重置成功！");
         }else{
          this.$Toast(res.data.msg);
         }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    getIndex() {
      indexdata({
        agentid: localStorage.getItem("agentids"),
      })
        .then((res) => {
          this.list = res.data.data.agents;
          this.store = res.data.data.store;
          this.agent = res.data.data.agent;
          console.log(res);
        })
        .catch((error) => {
          console.log(error);
        });
    },
    btn1(item) {
      localStorage.setItem("adminid", item.id);
      this.$router.push({
        path: "/record1",
      });
    },
    btn2(item) {
      localStorage.setItem("adminid", item.id);
      this.$router.push({
        path: "/record2",
      });
    },
  },
};
</script>

<style scoped>
.content {
  position: relative;
  padding-bottom: 2rem;
  overflow: hidden;
  width: 100%;
  min-height: 100vh;
  background: #e1f7fc;
}

.card1 {
  overflow: hidden;
  margin: 0.3rem auto 0;
  padding: 0 0.5rem 0.25rem 0.5rem;
  width: 84%;
  background: #fff;
  border-radius: 0.375rem;
}

.card1-title {
  margin-top: 0.2rem;
  font-size: 0.4125rem;
  font-weight: 600;
  color: #000;
}

.card1-text {
  flex: 1;
  display: inline-block;
  margin: 0.25rem 0 0 0.2rem;
  font-size: 0.3125rem;
  font-weight: 600;
  color: #000;
}

.card1-text1 {
  margin: 0.25rem 0 0 0.2rem;
  font-size: 0.3125rem;
  font-weight: 600;
  color: #000;
  text-align: center;
}

.btn {
  margin-top: 0.6rem;
  display: flex;
  /* 应用Flex布局 */
  justify-content: space-between;
  /* 控制盒子之间的对齐方式 */
}

.btn1 {
  padding: 0 .3rem;
  height: 0.75rem;
  color: #000;
  text-align: center;
  line-height: 0.75rem;
  border-radius: 0.375rem;
  background-color: #3cc9e8;
}

.btn4 {
  margin: 20px 30px 20px 0;
  float: right;
  width: 2.4rem;
  height: 0.75rem;
  color: #000;
  text-align: center;
  line-height: 0.75rem;
  border-radius: 0.375rem;
  background-color: #3cc9e8;
}

.s-card-text {
  margin: 20px 30px 20px 20px;
  height: 0.75rem;
  line-height: 0.75rem;
  float: left;
  color: #000;
  font-size: 0.45rem;
  font-weight: 600;
}

.btn2 {
  padding: 0 .3rem;
  height: 0.75rem;
  line-height: 0.75rem;
  text-align: center;
  color: #000;
  border-radius: 0.375rem;
  background-color: #ffbe4c;
}
.btn-new {
  display: inline-block;
  padding: .1rem .2rem;
  color: #fff;
  border-radius: 0.375rem;
  background-color: #f44;
}
.btn-news {
  display: inline-block;
  padding: .1rem .2rem;
  color: #fff;
  border-radius: 0.375rem;
  background-color: #07c160;
}
.sao {
  margin: 2rem auto 0;
  width: 60%;
  text-align: center;
  height: 1rem;
  line-height: 1rem;
  font-size: 0.35rem;
  border-radius: 0.5rem;
  background-color: #ffbe4c;
  font-weight: 600;
}

.addStore {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 1rem;
  font-size: .4rem;
  text-align: center;
  color: #AD3516;
  background: linear-gradient(180deg, #FFE9C6, #FFD584);
  box-shadow: 0px 3px 8px 0px rgba(150, 51, 20, 0.42);
  line-height: 1rem;
  border-radius: .5rem;
}
</style>